package com.rt.cloud.auth.config.login;

import org.springframework.security.oauth2.common.exceptions.InvalidScopeException;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.OAuth2RequestValidator;
import org.springframework.security.oauth2.provider.TokenRequest;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("requestValidator")
public class UinteRequestValidator implements OAuth2RequestValidator {

    @Override
    public void validateScope(AuthorizationRequest authorizationRequest, ClientDetails client) throws InvalidScopeException {
        //在这里检查用户的登陆失败次数
        Map<String, String> requestParameters = authorizationRequest.getRequestParameters();
        String username = requestParameters.get("username");
        System.out.println("AuthorizationRequest:"+ username);
    }

    // 成功 或 失败， 这里都会执行, 应该是发过来的请求信息
    @Override
    public void validateScope(TokenRequest tokenRequest, ClientDetails client) throws InvalidScopeException {
        //在这里检查用户的登陆失败次数
        Map<String, String> requestParameters = tokenRequest.getRequestParameters();
        String username = requestParameters.get("username");
    }

}
